<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class SetBank extends AdminController{
	public $_validation = null;
	function __construct(){
		parent::__construct();
		$this->load->model('MSetBank');
		$this->_validation = Array();
	}

	/**
     *  玩家列表
	 */
	function index(){
		//$this->output->enable_profiler(TRUE);
		$this->load->library('FormFilter');
		$this->load->helper('formfilter');
		
		$this->formfilter->addFilter('user.id', 'where');
		$this->formfilter->addFilter('user.set_bank_code', 'where');
		$this->formfilter->addFilter('user.account','where');
		$this->formfilter->addFilter('user.status','where');
		
		$limit = $this->pagination($this->MSetBank->getCount());
		$list = $this->MSetBank->getList($limit);

		$this->assign('list', $list);
		$this->layout();
	}
	
	function postresetcode(){
	    if(!$this->p->edit){
	        //权限不足
	        show_error(l('user_has_nopower'));
	    }
	    if(!$this->input->post()){
	        show_error('提交数据错误！');
	    }
	    $redirectUrl = site_url($this->_thisModule.$this->_thisController.'/setbank');
	    $this->load->model('MBankInfo');
	    $set_bank_code = $this->input->post('setBankCode');
	    if(!$this->MBankInfo->getAll(array('code'=>$set_bank_code))){
	        errorAndRedirect('没有找到给定的自有通道编号【 '.$set_bank_code.' 】',$redirectUrl);
	    }
	    
	    $user_ids = $this->input->post('ids');
	    $userIdArr = explode(',', $user_ids);
	    if($this->MSetBank->updateBankCode($set_bank_code,$userIdArr)){
	        successAndRedirect('批量更新自有通道编号成功！',$redirectUrl);
	    }else{
	        errorAndRedirect('批量更新自有通道编号失败！',$redirectUrl);
	    }
	}

}